﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.collections {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class TradeCollectableCommand extends Command {

        public var event:InfoEvent;
        public var collectableModel:CollectableModel;
        public var worldFactory:WorldFactory;

        override public function execute():void{
            var _local1:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, this.onResult);
            _local1.addRequest("trade_collection", {id:this.event.id, to:this.event.info});
            dispatch(_local1);
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Object;
            if (_arg1.success){
                _local2 = _arg1.data.trade_collection;
                if (((_local2.changes) && (!((_local2.changes == null))))){
                    this.updateChanges(_local2.changes);
                };
                if (((_local2.pet) && (!((_local2.pet == null))))){
                    if (_local2.pet[ProtocolConstants.STATE] == GameConstants.STATE_BABY){
                        this.initBaby(_local2.pet);
                    } else {
                        this.initElder(_local2.pet);
                    };
                };
                this.collectableModel.tradeInCollection(this.event.id);
                this.track();
            };
        }
        private function track():void{
            var _local1:Object = {type:"event", st1:"collections", st2:this.event.id, st3:this.event.info};
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _local1));
        }
        private function updateChanges(_arg1:Object):void{
            dispatch(new InfoEvent(EventConstants.UPDATE_USER_DATA, null, _arg1));
        }
        private function initBaby(_arg1:Object):void{
            var _local2:ITreatable = (this.worldFactory.createActor(_arg1) as ITreatable);
            var _local3:InfoEvent = new InfoEvent(EventConstants.CREATE_BABY, _local2.roomId, _arg1);
            dispatch(_local3);
        }
        private function initElder(_arg1:Object):void{
            dispatch(new InfoEvent(EventConstants.LOAD_PATIENT_ASSET, null, _arg1));
        }

    }
}//package net.wooga.pets.controllers.collections 
